﻿#include <QMessageBox>
#include <QFile>
#include <QStyleFactory>
#include <QMenu>
#include <QTimer>
#include "CRobPointConfigDialog.h"
#include "CHeader.h"
#include "CPanItemConfig.h"
#include "CSensorItemConfig.h"

CRobPointConfigDialog::CRobPointConfigDialog(QString sSceneGuid, QString sPointGuid, QString sPointName, CDevBase* pDev, CPolArea* pPolArea, CRBaseData* pBasicData, QWidget *parent)
	:m_sGuid(sSceneGuid),m_sPointGuid(sPointGuid),m_sPointName(sPointName),m_pDev(pDev),m_pPolAreaOld(pPolArea),m_pBasicData(pBasicData), QDialog(parent)
{
	ui.setupUi(this);
	setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
	m_sCopyItemGuid = "";
	m_bFristOpen = false;
	setStyleSheetFile();
	m_pDevData = (CDevDataBase*)pDev->m_pDevDataBase;
	m_nSpeed = m_pDevData->m_dRobRunSpeedSet.toFloat() * 10;
	m_nIsMove = 0;
	m_pTimer = new QTimer(this);
	m_pTimer->setTimerType(Qt::TimerType::PreciseTimer);
	connect(m_pTimer, &QTimer::timeout, this, &CRobPointConfigDialog::slotRefushData);
	m_pTimer->start(1000);
	initUI();
	initConnect();
	refushPointList();
	setVideoData();
}

CRobPointConfigDialog::~CRobPointConfigDialog()
{}

void CRobPointConfigDialog::refushPointList()
{
	if (m_pTreeModel != nullptr)
	{
		for (int i = 0; i < m_pTreeModel->rowCount(); i++)
		{
			QStandardItem *pItem = m_pTreeModel->item(i);

			for (int j = 0; j < pItem->rowCount(); j++)
			{
				QStandardItem *SubpItem = pItem->child(i);
				delete SubpItem;
				SubpItem = nullptr;
			}
			pItem->setRowCount(0);
			delete pItem;
			pItem = nullptr;
		}
		m_pTreeModel->setRowCount(0);
	}
	int nIndex = 0;
	//拿到巡检点数组
	CPolPoint* pPolPoint = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid];
	QStandardItem *pItem = new QStandardItem(m_sPointName);
	pItem->setIcon(QIcon(":/icon/Rob/Point.png"));
	pItem->setData(m_sPointGuid, 300);
	m_pTreeModel->setItem(nIndex, pItem);

	int k = 0;
	QString sFriteGuid = "";
	int nFriteItemType = -1;
	QString sFriteName = "";
	QVector<CPolItem*> vecItem = pPolPoint->m_mapPolItem.values().toVector();
	qSort(vecItem.begin(), vecItem.end(), sortPolItem);
	for (int i = 0; i < vecItem.size(); i++)
	{
		CPolItem* pPolItem = vecItem[i];
		if (i == 0)
		{
			sFriteGuid = pPolItem->m_sItemGuid;
			nFriteItemType = pPolItem->m_nDevType;
			sFriteName = pPolItem->m_sItemName;
		}
		QStandardItem* pChildItem = new QStandardItem(pPolItem->m_sItemName);
		pChildItem->setIcon(QIcon(":/icon/Rob/TaskMode.png"));
		pChildItem->setData(pPolItem->m_sItemGuid, 300);//将巡检项的Guid设置为300属性
		pChildItem->setData(pPolItem->m_nDevType, 301);//将巡检项的巡检类型设置为301属性
		pItem->setChild(k, pChildItem);
		k++;
	}
	/*for (QMap<QString, CPolItem*>::iterator itor = pPolPoint->m_mapPolItem.begin();
		itor != pPolPoint->m_mapPolItem.end(); itor++)
	{
		CPolItem* pPolItem = itor.value();
		QStandardItem* pChildItem = new QStandardItem(itor.value()->m_sItemName);
		pChildItem->setIcon(QIcon(":/icon/Rob/TaskMode.png"));
		pChildItem->setData(itor.key(), 300);//将巡检项的Guid设置为300属性
		pChildItem->setData(pPolItem->m_nDevType, 301);//将巡检项的巡检类型设置为301属性
		pItem->setChild(k, pChildItem);
		k++;
	}*/
	//最后将树完全展开
	ui.treeView->expandAll();
	if (m_bFristOpen == false)
	{
		showItem(sFriteGuid, sFriteName, nFriteItemType);
		m_bFristOpen = true;
	}
}

void CRobPointConfigDialog::setStyleSheetFile()
{
	QString sQssPath = ":/qss/styleSheet.css";
	QFile qss(sQssPath);
	qss.open(QFile::ReadOnly);
	this->setStyleSheet(qss.readAll());
}

void CRobPointConfigDialog::initConnect()
{
	connect(ui.treeView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(slotCustomContextMenu(const QPoint &)));//连接点击右键信号与槽函数
	connect(ui.treeView, &QTreeView::doubleClicked, this, &CRobPointConfigDialog::treeViewTemplateDoubleClicked);
	connect(ui.pushButtonAddCamerItem, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonAddCarmerItem);
	connect(ui.pushButtonAddSensorItem, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonAddSensorItem);
	connect(ui.pushButtonExpand, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonExpand);
	connect(ui.pushButtonShrink, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonShrink);
	connect(ui.widgetControlButton->ui.pushButtonDeSpeed, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonDeSpeedClicked);
	connect(ui.widgetControlButton->ui.pushButtonAddSpeed, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonAddSpeedClicked);
	connect(ui.widgetControlButton->ui.pushButtonRobResetLoc, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonResetLocClicked);
	connect(ui.widgetControlButton->ui.pushButtonTalkBackFunc, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonTalkBackFuncClicked);
	connect(ui.widgetControlButton->ui.pushButtonTalkBackClose, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonTalkBackCloseClicked);
	connect(ui.widgetControlButton->ui.pushButtonLampLightOpen, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonLampLightOpenClicked);
	connect(ui.widgetControlButton->ui.pushButtonLampLightClose, &QPushButton::clicked, this, &CRobPointConfigDialog::slotPushButtonLampLightCloseClicked);

	connect(ui.widgetControlButton->ui.pushButtonFocusingAdd, &QPushButton::pressed, this, &CRobPointConfigDialog::slotPushButtonFocusingAddClicked);
	connect(ui.widgetControlButton->ui.pushButtonFocusingAdd, &QPushButton::released, this, &CRobPointConfigDialog::slotPushButtonFocusingAddRelease);
	connect(ui.widgetControlButton->ui.pushButtonFocusingSubtract, &QPushButton::pressed, this, &CRobPointConfigDialog::slotPushButtonFocusingSubtractClicked);
	connect(ui.widgetControlButton->ui.pushButtonFocusingSubtract, &QPushButton::released, this, &CRobPointConfigDialog::slotPushButtonFocusingSubtractRelease);

	//CPushButtonA中的槽函数绑定
	//机器人控制部分
	connect(ui.widgetControlButton->ui.pushButtonControl, SIGNAL(PressedUp()), this, SLOT(slotRobRunUp()));       //上
	connect(ui.widgetControlButton->ui.pushButtonControl, SIGNAL(PressedDown()), this, SLOT(slotRobRunDown()));   //下
	connect(ui.widgetControlButton->ui.pushButtonControl, SIGNAL(PressedLeft()), this, SLOT(slotRobRunLeft()));  //前进
	connect(ui.widgetControlButton->ui.pushButtonControl, SIGNAL(PressedRigth()), this, SLOT(slotRobRunRight()));  //后退
	connect(ui.widgetControlButton->ui.pushButtonControl, SIGNAL(ReleasedUp()), this, SLOT(slotRobRunStop()));    //停止运动
	connect(ui.widgetControlButton->ui.pushButtonControl, SIGNAL(ReleasedDown()), this, SLOT(slotRobRunStop()));  //停止运动
	connect(ui.widgetControlButton->ui.pushButtonControl, SIGNAL(ReleasedLeft()), this, SLOT(slotRobRunStop()));  //停止运动
	connect(ui.widgetControlButton->ui.pushButtonControl, SIGNAL(ReleasedRigth()), this, SLOT(slotRobRunStop())); //停止运动
	connect(ui.widgetControlButton->ui.pushButtonControl, SIGNAL(ClieckedCenter()), this, SLOT(slotRobCenter())); //中间按钮

	//云台控制部分
	connect(ui.widgetControlButton->ui.PushButtenYt, SIGNAL(PressedUp()), this, SLOT(slotYtUpP()));               //云台 按下 上
	connect(ui.widgetControlButton->ui.PushButtenYt, SIGNAL(PressedDown()), this, SLOT(slotYtDownP()));           //云台 按下 下
	connect(ui.widgetControlButton->ui.PushButtenYt, SIGNAL(PressedLeft()), this, SLOT(slotYtLeftP()));           //云台 按下 左
	connect(ui.widgetControlButton->ui.PushButtenYt, SIGNAL(PressedRigth()), this, SLOT(slotYtRigthP()));         //云台 按下 右
	connect(ui.widgetControlButton->ui.PushButtenYt, SIGNAL(ReleasedUp()), this, SLOT(slotYtUpR()));              //云台 松开 上
	connect(ui.widgetControlButton->ui.PushButtenYt, SIGNAL(ReleasedDown()), this, SLOT(slotYtDownR()));          //云台 松开 下
	connect(ui.widgetControlButton->ui.PushButtenYt, SIGNAL(ReleasedLeft()), this, SLOT(slotYtLeftR()));          //云台 松开 左
	connect(ui.widgetControlButton->ui.PushButtenYt, SIGNAL(ReleasedRigth()), this, SLOT(slotYtRigthR()));        //云台 松开 右
	connect(ui.widgetControlButton->ui.PushButtenYt, SIGNAL(ClieckedCenter()), this, SLOT(slotYtCenter()));        //中间按钮
}

void CRobPointConfigDialog::initUI()
{
	QIcon icon(":/icon/Rob/Rob.ico");
	setWindowIcon(icon);
	setWindowTitle(A2T("巡检点配置"));

	ui.widgetControlButton->ui.pushButtonControl->SetPushButtenText(A2T("确定"), A2T("上升"), A2T("下降"), A2T("后退"), A2T("前进"));
	ui.widgetControlButton->ui.PushButtenYt->SetPushButtenText(A2T("确定"), A2T("上"), A2T("下"), A2T("左"), A2T("右"));

	m_pTreeModel = new QStandardItemModel();
	ui.treeView->setModel(m_pTreeModel);
	ui.treeView->setStyle(QStyleFactory::create("windows"));
	ui.treeView->setSelectionMode(QAbstractItemView::SingleSelection);
	ui.treeView->setFrameShape(QFrame::NoFrame);
	ui.treeView->header()->hide();
	ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu);
	ui.treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	ui.treeView->setFocusPolicy(Qt::NoFocus);
	CustomItemDelegate *delegate = new CustomItemDelegate(ui.treeView);
	ui.treeView->setItemDelegate(delegate);
}

void CRobPointConfigDialog::setVideoData()
{
	ui.widgetVideo->m_pDev = m_pDev;
	ui.widgetVideo->m_sGuid = m_sGuid;
	ui.widgetVideo->playVideo();
}

void CRobPointConfigDialog::showItem(QString sItemGuid,QString sItemName, int nItemType)
{
	//根据巡检项类型显示不同的配置界面
	if (nItemType == 1)//云台巡检项
	{
		CPanItemConfig* pPanItemConfig = new CPanItemConfig(m_sGuid, m_sPointGuid, m_pDev, m_pPolAreaOld,m_pBasicData);
		connect(pPanItemConfig, SIGNAL(sigRefushUI()), this, SLOT(slotRefushUI()));
		connect(this, SIGNAL(sigSetPanPreset()), pPanItemConfig, SLOT(slotSetPanPreset()));
		connect(this, SIGNAL(sigGetRobZ()), pPanItemConfig, SLOT(slotGetRobZ()));

		pPanItemConfig->m_nType = 1;//修改类型
		pPanItemConfig->setTitle();
		CPolItemCamer* pItem = (CPolItemCamer*)m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[sItemGuid];
		pPanItemConfig->setData(sItemGuid, sItemName, pItem->m_nAlarmLevel, pItem->m_nDevTypeCode, pItem->m_nTackPicture, pItem->m_nCheckType, pItem->m_nDataType, pItem->m_nCollectIndex,
			pItem->m_sDataThreadHoldHH.toDouble(), pItem->m_sDataThreadHoldLL.toDouble(), pItem->m_sDataThreadHoldH.toDouble(), pItem->m_sDataThreadHoldL.toDouble(),
			pItem->m_dItemZ, pItem->m_dCollectTime, pItem->m_dAngelCamer, pItem->m_dCollectInterval, pItem->m_nBelong,pItem->m_nCollectCheckType,pItem->m_nCollectRollerNum, pItem->m_dRollerOffdetDis,pItem->m_nIsExecAI, pItem->m_nIsShowPdf);
		ui.gridLayoutConfig->addWidget(pPanItemConfig);
	}
	else if (nItemType == 0)
	{
		CSensorItemConfig* pSensorItemConfig = new CSensorItemConfig(m_sGuid, m_pDev);
		connect(pSensorItemConfig, SIGNAL(sigRefushUI()), this, SLOT(slotRefushUI()));
		pSensorItemConfig->m_pPolAreaOld = m_pPolAreaOld;
		pSensorItemConfig->m_sPointGuid = m_sPointGuid;
		pSensorItemConfig->m_nType = 1;//修改类型
		pSensorItemConfig->setTitle();
		CPolItemSensor* pItem = (CPolItemSensor*)m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[sItemGuid];
		pSensorItemConfig->setData(pItem->m_sItemName, pItem->m_nDevTypeCode, pItem->m_sItemGuid, pItem->m_nAlarmLevel,
			pItem->m_sDataThreadHoldHH.toDouble(), pItem->m_sDataThreadHoldLL.toDouble(), pItem->m_sDataThreadHoldH.toDouble(),
			pItem->m_sDataThreadHoldL.toDouble(),pItem->m_nBelong,pItem->m_nCheckType,pItem->m_nCollectCheckType,pItem->m_nCollectRollerNum,pItem->m_nCollectIndex,pItem->m_dCollectInterval);
		ui.gridLayoutConfig->addWidget(pSensorItemConfig);
	}
}

void CRobPointConfigDialog::closeConfigWidget()
{
	QLayoutItem* child;
	while ((child = ui.gridLayoutConfig->takeAt(0)) != nullptr)
	{
		if (QWidget *widget = child->widget())
		{
			ui.gridLayoutConfig->removeWidget(widget);
			delete widget;
		}
		delete child;
	}
}

void CRobPointConfigDialog::pasteItem()
{
	if (m_sCopyItemGuid == "")
	{
		messageBox(0, A2T("请先复制巡检项"));
		return;
	}
	CPolPoint* pPoint = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid];
	for (QMap<QString, CPolItem*>::iterator itor = pPoint->m_mapPolItem.begin(); itor != pPoint->m_mapPolItem.end(); itor++)
	{
		CPolItem* pItem = itor.value();
		if (m_sCopyItemGuid == pItem->m_sItemGuid)//找到了需要复制的巡检项
		{
			CPolItem* pNewItem;
			if (pItem->m_nDevType == 0)//传感器类型
			{
				pNewItem = new CPolItemSensor();
			}
			else if(pItem->m_nDevType == 1)//云台类型
			{
				pNewItem = new CPolItemCamer();
			}
			QString sGuid = createGuid();
			pItem->copyData(pNewItem);
			pNewItem->m_nIndex = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->getItemMaxIndex() + 1;
			pNewItem->m_sItemGuid = sGuid;
			pNewItem->m_nItemStatus = 1;//新增巡检项
			pPoint->m_mapPolItem.insert(sGuid, pNewItem);
			if (pPoint->m_nPointStatus == 0)
			{
				pPoint->m_nPointStatus = 2;
			}
			else if (pPoint->m_nPointStatus == 1)
			{
				pPoint->m_nPointStatus = 1;
			}
			else if (pPoint->m_nPointStatus == 2)
			{
				pPoint->m_nPointStatus = 2;
			}
			m_sCopyItemGuid = "";
			slotRefushUI();
			break;
		}
		else
		{
			continue;
		}
	}
}

void CRobPointConfigDialog::slotRefushData()
{
	QString sStr = "";
	if (m_nIsMove == 1)//机器人运动中
	{
		float fSpeed = m_pDevData->m_sRobCurrSpeed.toFloat();             //当前速度
		sStr = QString::number(fSpeed) + "m/s";
	}
	else//显示设定速度
	{
		float fSpeed = m_pDevData->m_dRobRunSpeedSet.toFloat();             //设定速度
		sStr = QString::number(fSpeed) + "m/s";
	}
	ui.widgetControlButton->ui.pushButtonControl->SetPushButtenText(sStr);
	ui.widgetControlButton->ui.pushButtonControl->update();
}

void CRobPointConfigDialog::slotRefushUI()
{
	if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 0)//只有巡检点之前的状态是未改变的时候才将修改状态改为2
	{
		m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
	}
	refushPointList();
}

void CRobPointConfigDialog::slotCustomContextMenu(const QPoint & point)
{
	QModelIndex curIndex = ui.treeView->indexAt(point); // 取到当前的节点

	if (!curIndex.isValid())//当前的节点是无效的
	{
		return;
	}

	QStandardItem *item = m_pTreeModel->itemFromIndex(curIndex);
	if (!curIndex.parent().isValid())//当前节点的父节点无效，证明是1级节点->巡检点
	{
		QMenu menu(this);
		QAction aSetName;
		QAction aAddPanItem;
		QAction aAddSensorItem;
		QAction aPaste;
		aSetName.setText(A2T("保存巡检点名称"));
		aAddPanItem.setText(A2T("增加云台巡检项"));
		aAddSensorItem.setText(A2T("增加传感器巡检项"));
		aPaste.setText(A2T("粘贴巡检项"));
		menu.addAction(&aSetName);
		menu.addAction(&aAddPanItem);
		menu.addAction(&aAddSensorItem);
		menu.addAction(&aPaste);
		QAction* pAction = menu.exec(QCursor::pos());
		if (pAction && pAction->text() == A2T("保存巡检点名称"))
		{
			QString sPointGuid = item->data(300).toString();
			QString sPointNewName = item->text();
			QString sErrMsg = "";
			CPolPoint* pPoint = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid];
			pPoint->m_sPointName = sPointNewName;
			if (pPoint->m_nPointStatus == 0)//之前未变
			{
				pPoint->m_nPointStatus = 2;
			}
			else if (pPoint->m_nPointStatus == 1)//之前新增
			{
				pPoint->m_nPointStatus = 1;
			}
			else if (pPoint->m_nPointStatus == 2)//之前是修改过的
			{
				pPoint->m_nPointStatus = 2;
			}
		}
		else if (pAction && pAction->text() == A2T("增加云台巡检项"))
		{
			//首先将ui中的配置界面全部清空
			QLayoutItem* child;
			while ((child = ui.gridLayoutConfig->takeAt(0)) != nullptr)
			{
				if (QWidget *widget = child->widget())
				{
					ui.gridLayoutConfig->removeWidget(widget);
					delete widget;
				}
				delete child;
			}
			QString sItemGuid = item->data(300).toString();
			CPanItemConfig* pPanItemConfig = new CPanItemConfig(m_sGuid,m_sPointGuid,m_pDev,m_pPolAreaOld, m_pBasicData);
			connect(pPanItemConfig, SIGNAL(sigRefushUI()), this, SLOT(slotRefushUI()));
			connect(this, SIGNAL(sigSetPanPreset()), pPanItemConfig, SLOT(slotSetPanPreset()));
			connect(this, SIGNAL(sigGetRobZ()), pPanItemConfig, SLOT(slotGetRobZ()));
			pPanItemConfig->m_nType = 0;//增加类型
			pPanItemConfig->setTitle();
			ui.gridLayoutConfig->addWidget(pPanItemConfig);
		}
		else if (pAction && pAction->text() == A2T("增加传感器巡检项"))
		{
			//首先将ui中的配置界面全部清空
			QLayoutItem* child;
			while ((child = ui.gridLayoutConfig->takeAt(0)) != nullptr)
			{
				if (QWidget *widget = child->widget())
				{
					ui.gridLayoutConfig->removeWidget(widget);
					delete widget;
				}
				delete child;
			}
			QString sItemGuid = item->data(300).toString();
			CSensorItemConfig* pSensorItemConfig = new CSensorItemConfig(m_sGuid, m_pDev);
			connect(pSensorItemConfig, SIGNAL(sigRefushUI()), this, SLOT(slotRefushUI()));
			pSensorItemConfig->m_pPolAreaOld = m_pPolAreaOld;
			pSensorItemConfig->m_sPointGuid = m_sPointGuid;
			pSensorItemConfig->m_sGuid = m_sGuid;
			pSensorItemConfig->m_nType = 0;//增加类型
			pSensorItemConfig->setTitle();
			ui.gridLayoutConfig->addWidget(pSensorItemConfig);
		}
		else if (pAction && pAction->text() == A2T("粘贴巡检项"))
		{
			pasteItem();
		}
	}
	else//当前的节点父节点有效，证明是二级节点-》巡检项
	{
		QMenu menu(this);
		QAction aDelete;//删除巡检项
		QAction aUp;//上移
		QAction aDown;//下移
		QAction aCopy;//复制巡检项

		aDelete.setText(A2T("删除巡检项"));
		aUp.setText(A2T("上移"));
		aDown.setText(A2T("下移"));
		aCopy.setText(A2T("复制此巡检项"));

		menu.addAction(&aDelete);
		menu.addAction(&aUp);
		menu.addAction(&aDown);
		menu.addAction(&aCopy);
		QAction* pAction = menu.exec(QCursor::pos());
		if (pAction && pAction->text() == A2T("删除巡检项"))
		{
			QString sItemName = item->text();
			QString sItemGuid = item->data(300).toString();
			int nType= item->data(301).toInt();
			//然后刷新全局的数据
			CPolItem* pItem = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[sItemGuid];
			m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem.remove(sItemGuid);
			//判断上层巡检点的状态
			if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 0)//未变
			{
				m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
			}
			else if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 1)//新增
			{
				m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 1;
			}
			else if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 2)//修改过
			{
				m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
			}
			delete pItem;
			pItem = nullptr;
			//删除巡检项后，通知上层将界面全部关掉
			closeConfigWidget();
			refushPointList();
		}
		else if (pAction && pAction->text() == A2T("上移"))
		{
			QString sItemGuid = item->data(300).toString();
			int row = curIndex.row();
			if (row <= 0)
			{
				messageBox(0, A2T("无法移动"));
				return;
			}
			QModelIndex prevIndex = curIndex.sibling(row - 1, curIndex.column());
			QStandardItem *prevItem = m_pTreeModel->itemFromIndex(prevIndex);
			QString sPrevItemGuid = prevItem->data(300).toString();
			CPolItem* pItem = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[sItemGuid];
			CPolItem* pPrevItem = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[sPrevItemGuid];
			//首先判断是否移动的是云台巡检项，要保证移动后云台巡检项始终在本体巡检项后面
			if (pItem->m_nDevType == 0)
			{
				messageBox(0, A2T("只能移动云台巡检项"));
				return;
			}
			if (pPrevItem->m_nDevType == 0)
			{
				messageBox(0, A2T("只能移动云台巡检项"));
				return;
			}
			//互换序号
			int nItemIndex = pItem->m_nIndex;
			pItem->m_nIndex = pPrevItem->m_nIndex;
			pPrevItem->m_nIndex = nItemIndex;
			if (pItem->m_nItemStatus != 1)
			{
				pItem->m_nItemStatus = 2;
			}
			if (pPrevItem->m_nItemStatus != 1)
			{
				pPrevItem->m_nItemStatus = 2;
			}
			if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 0)
			{
				m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
			}
			else if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 1)
			{
				m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 1;
			}
			else if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 2)
			{
				m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
			}
			refushPointList();
		}
		else if (pAction && pAction->text() == A2T("下移"))
		{
			QString sItemGuid = item->data(300).toString();
			int row = curIndex.row();
			int column = curIndex.column();
			QStandardItem* parentItem = m_pTreeModel->itemFromIndex(curIndex.parent());

			if (row >= parentItem->rowCount() - 1)
			{
				messageBox(0, A2T("无法移动"));
				return;
			}
			QModelIndex nextIndex = curIndex.sibling(row + 1, curIndex.column());
			QStandardItem *nextItem = m_pTreeModel->itemFromIndex(nextIndex);
			QString sNextItemGuid = nextItem->data(300).toString();
			CPolItem* pItem = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[sItemGuid];
			CPolItem* pNextItem = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[sNextItemGuid];
			//首先判断是否移动的是云台巡检项，要保证移动后云台巡检项始终在本体巡检项后面
			if (pItem->m_nDevType == 0)
			{
				messageBox(0, A2T("只能移动云台巡检项"));
				return;
			}
			if (pNextItem->m_nDevType == 0)
			{
				messageBox(0, A2T("只能移动云台巡检项"));
				return;
			}
			//互换序号
			int nItemIndex = pItem->m_nIndex;
			pItem->m_nIndex = pNextItem->m_nIndex;
			pNextItem->m_nIndex = nItemIndex;
			if (pItem->m_nItemStatus != 1)
			{
				pItem->m_nItemStatus = 2;
			}
			if (pNextItem->m_nItemStatus != 1)
			{
				pNextItem->m_nItemStatus = 2;
			}
			if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 0)
			{
				m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
			}
			else if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 1)
			{
				m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 1;
			}
			else if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 2)
			{
				m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
			}
			refushPointList();
		}
		else if (pAction && pAction->text() == A2T("复制此巡检项"))
		{
			QString sItemGuid = item->data(300).toString();
			m_sCopyItemGuid = sItemGuid;
		}
	}
}

void CRobPointConfigDialog::slotPushButtonAddCarmerItem()
{
	//首先将ui中的配置界面全部清空
	QLayoutItem* child;
	while ((child = ui.gridLayoutConfig->takeAt(0)) != nullptr)
	{
		if (QWidget *widget = child->widget())
		{
			ui.gridLayoutConfig->removeWidget(widget);
			delete widget;
		}
		delete child;
	}
	CPanItemConfig* pPanItemConfig = new CPanItemConfig(m_sGuid, m_sPointGuid, m_pDev, m_pPolAreaOld, m_pBasicData);
	connect(pPanItemConfig, SIGNAL(sigRefushUI()), this, SLOT(slotRefushUI()));
	connect(this, SIGNAL(sigSetPanPreset()), pPanItemConfig, SLOT(slotSetPanPreset()));
	connect(this, SIGNAL(sigGetRobZ()), pPanItemConfig, SLOT(slotGetRobZ()));
	pPanItemConfig->m_nType = 0;//增加类型
	pPanItemConfig->setTitle();
	ui.gridLayoutConfig->addWidget(pPanItemConfig);
}

void CRobPointConfigDialog::slotPushButtonAddSensorItem()
{
	//首先将ui中的配置界面全部清空
	QLayoutItem* child;
	while ((child = ui.gridLayoutConfig->takeAt(0)) != nullptr)
	{
		if (QWidget *widget = child->widget())
		{
			ui.gridLayoutConfig->removeWidget(widget);
			delete widget;
		}
		delete child;
	}
	CSensorItemConfig* pSensorItemConfig = new CSensorItemConfig(m_sGuid,m_pDev);
	connect(pSensorItemConfig, SIGNAL(sigRefushUI()), this, SLOT(slotRefushUI()));
	pSensorItemConfig->m_pPolAreaOld = m_pPolAreaOld;
	pSensorItemConfig->m_sPointGuid = m_sPointGuid;
	pSensorItemConfig->m_sGuid = m_sGuid;
	pSensorItemConfig->m_nType = 0;//增加类型
	pSensorItemConfig->setTitle();
	ui.gridLayoutConfig->addWidget(pSensorItemConfig);
}

//全部展开
void CRobPointConfigDialog::slotPushButtonExpand()
{
	ui.treeView->expandAll();
}

//全部收缩
void CRobPointConfigDialog::slotPushButtonShrink()
{
	ui.treeView->collapseAll();
}

void CRobPointConfigDialog::treeViewTemplateDoubleClicked(const QModelIndex &index)
{
	// 获取点击的节点
	QStandardItem *item = m_pTreeModel->itemFromIndex(index);

	// 判断节点是否是二级节点
	if (item && item->parent() && item->parent()->parent() == nullptr)
	{
		//首先将ui中的配置界面全部清空
		QLayoutItem* child;
		while ((child = ui.gridLayoutConfig->takeAt(0)) != nullptr)
		{
			if (QWidget *widget = child->widget())
			{
				ui.gridLayoutConfig->removeWidget(widget);
				delete widget;
			}
			delete child;
		}
		QString sItemName = item->text();
		QString sItemGuid = item->data(300).toString();
		int nItemType = item->data(301).toInt();
		//根据巡检项类型显示不同的配置界面
		if (nItemType == 1)//云台巡检项
		{
			CPanItemConfig* pPanItemConfig = new CPanItemConfig(m_sGuid,m_sPointGuid,m_pDev,m_pPolAreaOld, m_pBasicData);
			connect(pPanItemConfig, SIGNAL(sigRefushUI()), this, SLOT(slotRefushUI()));
			connect(this, SIGNAL(sigSetPanPreset()), pPanItemConfig, SLOT(slotSetPanPreset()));
			connect(this, SIGNAL(sigGetRobZ()), pPanItemConfig, SLOT(slotGetRobZ()));

			pPanItemConfig->m_nType = 1;//修改类型
			pPanItemConfig->setTitle();
			CPolItemCamer* pItem = (CPolItemCamer*)m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[sItemGuid];
			pPanItemConfig->setData(sItemGuid, sItemName, pItem->m_nAlarmLevel,pItem->m_nDevTypeCode, pItem->m_nTackPicture, pItem->m_nCheckType, pItem->m_nDataType, pItem->m_nCollectIndex,
				pItem->m_sDataThreadHoldHH.toDouble(), pItem->m_sDataThreadHoldLL.toDouble(), pItem->m_sDataThreadHoldH.toDouble(), pItem->m_sDataThreadHoldL.toDouble(),
				pItem->m_dItemZ, pItem->m_dCollectTime,pItem->m_dAngelCamer, pItem->m_dCollectInterval, pItem->m_nBelong, pItem->m_nCollectCheckType, pItem->m_nCollectRollerNum,pItem->m_dRollerOffdetDis,pItem->m_nIsExecAI, pItem->m_nIsShowPdf);
			ui.gridLayoutConfig->addWidget(pPanItemConfig);
		}
		else if (nItemType == 0)
		{
			CSensorItemConfig* pSensorItemConfig = new CSensorItemConfig(m_sGuid, m_pDev);
			connect(pSensorItemConfig, SIGNAL(sigRefushUI()), this, SLOT(slotRefushUI()));
			pSensorItemConfig->m_pPolAreaOld = m_pPolAreaOld;
			pSensorItemConfig->m_sPointGuid = m_sPointGuid;
			pSensorItemConfig->m_nType = 1;//修改类型
			pSensorItemConfig->setTitle();
			CPolItemSensor* pItem = (CPolItemSensor*)m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[sItemGuid];
			pSensorItemConfig->setData(pItem->m_sItemName,pItem->m_nDevTypeCode,pItem->m_sItemGuid,pItem->m_nAlarmLevel,
				pItem->m_sDataThreadHoldHH.toDouble(), pItem->m_sDataThreadHoldLL.toDouble(), pItem->m_sDataThreadHoldH.toDouble(),
				pItem->m_sDataThreadHoldL.toDouble(), pItem->m_nBelong,pItem->m_nCheckType, pItem->m_nCollectCheckType, pItem->m_nCollectRollerNum, pItem->m_nCollectIndex, pItem->m_dCollectInterval);
			ui.gridLayoutConfig->addWidget(pSensorItemConfig);
		}
	}
	else
	{
		return;
	}
}

void CRobPointConfigDialog::slotPushButtonDeSpeedClicked()
{
	m_nSpeed--;
	if (m_nSpeed > 0)
	{
		if (m_nSpeed > 5)//速度限制
		{
			m_nSpeed = 5;
		}
	}
	else
	{
		m_nSpeed = 0;
	}
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCSetSpeed;
	stCtrInfo.m_nSpeed = m_nSpeed;
	m_pDev->ctrDev(stCtrInfo);
}

void CRobPointConfigDialog::slotPushButtonAddSpeedClicked()
{
	m_nSpeed++;
	if (m_nSpeed > 0)
	{
		if (m_nSpeed > 5)//速度限制
		{
			m_nSpeed = 5;
		}
	}
	else
	{
		m_nSpeed = 0;
	}
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCSetSpeed;
	stCtrInfo.m_nSpeed = m_nSpeed;
	m_pDev->ctrDev(stCtrInfo);
}

void CRobPointConfigDialog::slotPushButtonResetLocClicked()
{
	//触发是否复位
	int nResult = messageBox(3,A2T("是否确定按下复位按钮?"));
	if (QMessageBox::No == nResult || QMessageBox::Close == nResult)
	{
		return;
	}
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_pDev->m_sDevGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCinitRob;
	m_pDev->ctrDev(stCtrInfo);
}

void CRobPointConfigDialog::slotPushButtonTalkBackFuncClicked()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrDevType = enSubDev1;
	stCtrInfo.m_nCtrCmd = ECCamerCmdType::enCVoiceTalk;
	m_pDev->ctrDev(stCtrInfo);
}

void CRobPointConfigDialog::slotPushButtonTalkBackCloseClicked()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrDevType = enSubDev1;
	stCtrInfo.m_nCtrCmd = ECCamerCmdType::enCStopVoiceTalk;
	m_pDev->ctrDev(stCtrInfo);
}

void CRobPointConfigDialog::slotPushButtonLampLightOpenClicked()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrDevType = enSubDev1;
	stCtrInfo.m_nCtrCmd = ECCamerCmdType::enCLightPwoer;
	m_pDev->ctrDev(stCtrInfo);
}

void CRobPointConfigDialog::slotPushButtonLampLightCloseClicked()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrDevType = enSubDev1;
	stCtrInfo.m_nCtrCmd = ECCamerCmdType::enCStopLightPwoer;
	m_pDev->ctrDev(stCtrInfo);
}

//调焦+按钮槽函数
void CRobPointConfigDialog::slotPushButtonFocusingAddClicked()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrDevType = enSubDev1;
	stCtrInfo.m_nCtrCmd = ECCamerCmdType::enZoomAdd;
	m_pDev->ctrDev(stCtrInfo);
}
//调焦+按钮释放槽函数
void CRobPointConfigDialog::slotPushButtonFocusingAddRelease()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrDevType = enSubDev1;
	stCtrInfo.m_nCtrCmd = ECCamerCmdType::enZoomAddStop;
	m_pDev->ctrDev(stCtrInfo);
}

//调焦-按钮槽函数
void CRobPointConfigDialog::slotPushButtonFocusingSubtractClicked()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrDevType = enSubDev1;
	stCtrInfo.m_nCtrCmd = ECCamerCmdType::enZoomSubtract;
	m_pDev->ctrDev(stCtrInfo);
}

//调焦-按钮释放槽函数
void CRobPointConfigDialog::slotPushButtonFocusingSubtractRelease()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrDevType = enSubDev1;
	stCtrInfo.m_nCtrCmd = ECCamerCmdType::enZoomSubtractStop;
	m_pDev->ctrDev(stCtrInfo);
}

void CRobPointConfigDialog::slotRobRunUp()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCMoveUp;
	m_pDev->ctrDev(stCtrInfo);
}

void CRobPointConfigDialog::slotRobRunDown()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCMoveDown;
	m_pDev->ctrDev(stCtrInfo);
}

void CRobPointConfigDialog::slotRobRunRight()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCMoveForward;
	m_pDev->ctrDev(stCtrInfo);
	m_nIsMove = 1;
}

void CRobPointConfigDialog::slotRobRunLeft()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCMoveBackward;
	m_pDev->ctrDev(stCtrInfo);
	m_nIsMove = 1;
}

void CRobPointConfigDialog::slotRobRunStop()
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_sGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCNoCmd;
	m_pDev->ctrDev(stCtrInfo);
	m_nIsMove = 0;
}

void CRobPointConfigDialog::slotRobCenter()
{
	emit(sigGetRobZ());
}

void CRobPointConfigDialog::slotYtUpP()
{
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = true;
	info.m_bHasCtr = false;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enCTiltUp;
	m_pDev->ctrDev(info);
}

void CRobPointConfigDialog::slotYtDownP()
{
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = true;
	info.m_bHasCtr = false;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enCTiltDown;
	m_pDev->ctrDev(info);
}

void CRobPointConfigDialog::slotYtRigthP()
{
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = true;
	info.m_bHasCtr = false;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enCPanRight;//Modify++20240526
	m_pDev->ctrDev(info);
}

void CRobPointConfigDialog::slotYtLeftP()
{
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = true;
	info.m_bHasCtr = false;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enCPanLeft;//Modify++20240526
	m_pDev->ctrDev(info);
}

void CRobPointConfigDialog::slotYtUpR()
{
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = true;
	info.m_bHasCtr = false;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enCTiltUpStop;
	m_pDev->ctrDev(info);
}

void CRobPointConfigDialog::slotYtDownR()
{
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = true;
	info.m_bHasCtr = false;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enCTiltDownStop;
	m_pDev->ctrDev(info);
}

void CRobPointConfigDialog::slotYtRigthR()
{
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = true;
	info.m_bHasCtr = false;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enCPanLeftStop;
	m_pDev->ctrDev(info);
}

void CRobPointConfigDialog::slotYtLeftR()
{
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = true;
	info.m_bHasCtr = false;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enCPanRightStop;
	m_pDev->ctrDev(info);
}

void CRobPointConfigDialog::slotYtCenter()
{
	emit(sigSetPanPreset());
}
